<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of proveedor_model
 *
 * @author Marlon
 */
class proveedor_model extends CI_Model
{

    
    function __construct()
    {
        parent::__construct();
    
    }
    function insertarProveedor($datos){
         $this->db->insert('proveedor',$datos);    
    }
    function insertarCaracte($cartInsumo){
        $this->db->insert('caracteristicainsumo',$cartInsumo);
        return $this->db->insert_id();
    }
    function insertarInsumo($datoInsumo){
        $this->db->insert('insumo',$datoInsumo);
        return $this->db->insert_id(); ;
    }
    function insertarInsumoProveedor($datoInsuxProveedo){
        $this->db->insert('proveedorxinsumo',$datoInsuxProveedo); 
    }
    
    function buscarProveedor($idUsuario,$tipPer,$ruc,$razon,$docu,$nombs,$apellidos,$nomInsu){
        $cad="SELECT per.IdPersona as codPer,per.TipoDePersona as tipo, per.RUC as ruc, 
            per.RazonSocial as razon, per.Nombres as nomb, per.Apellidos as apellido,
            per.DNI as dni, ins.NombreInsumo as nomInsu from Persona per, proveedor prove ,insumo ins, proveedorxinsumo pi
            where per.IdPersona=prove.IdProveedor and pi.IdPersona=IdProveedor and pi.IdInsumo=ins.IdInsumo and prove.Usuario_IdUsuario=".$idUsuario;
        if ($ruc != "") {
            $cad = $cad . " AND per.RUC = $ruc";
        }
        if ($tipPer != "" && $tipPer != "Todos") {
            $cad = $cad . " AND per.TipoDePersona = '$tipPer'";
        }
        if ($razon != "") {
            $cad = $cad . " and per.RazonSocial like '%$razon%' ";
        }
        if ($docu != "") {
            $cad = $cad . " and per.DNI like '%$docu%' ";
        }
        if ($nombs != "") {
            $cad = $cad . " and per.Nombres like '%$nombs%' ";
        }
        if ($apellidos != "") {
            $cad = $cad . " and per.Apellidos like '%$apellidos%' ";
        }
        if ($nomInsu != "") {
            $cad = $cad . " and ins.NombreInsumo like '%$nomInsu%' ";
        }
        return $this->db->query($cad)->result_array();;
    }
 
}

?>